jQuery(document).ready(function($) {
	$('.cl_next').bind('click', function(e){
		e.preventDefault();
		e.stopPropagation();
		
		var page_container= $(this).closest('[nav_page]');
		var page_nav= $('.cl_nav', page_container);
		var link_container= $('.cl_nav .cl_link', page_container);
		var loading_container= $('.cl_nav .cl_loading', page_container);
		
		link_container.addClass('hide');
		loading_container.removeClass('hide');
		
		$.ajax({
			url: $(this).attr('href'),
			type: 'POST',
			data: {referer: cl_current_url_no_query},
			async: true, 
			cache: false,
			success: function(page){
				var new_page_container= $('<div />').html(page).find('[nav_page]');
				var new_page_nav= $('.cl_nav', new_page_container);
				var new_loading_container= $('.cl_nav .cl_link', new_page_container);
				var new_link_container= $('.cl_nav .cl_loading', new_page_container);			
				
				//Append new/next posts and page nav 
				page_container.after(new_page_container);
				
				//Remove current page nav
				page_nav.remove();
			},
			error: function(){
				link_container.removeClass('hide');
				loading_container.addClass('hide');				
			}
		});	
	});	
});

